package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TMedicinal;
import com.myProject.bean.TMeet;
import com.myProject.dao.MedicDao;
import com.myProject.dao.MeetDao;
import com.myProject.serves.MedicSev;
import com.myProject.serves.MeetSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class MedicSevImpl implements MedicSev {
    @Override
    public List<TMedicinal> getMedicList(TMedicinal tMedicinal) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MedicDao md = sqlSession.getMapper(MedicDao.class);
        List<TMedicinal> list = md.getMedicList(tMedicinal);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public PageInfo<TMedicinal> showMedicByPage(int pageNo, int pageSize, TMedicinal tMedicinal) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MedicDao md = sqlSession.getMapper(MedicDao.class);
        PageHelper.startPage(pageNo, pageSize);
        List<TMedicinal> list = md.getMedicList(tMedicinal);
        PageInfo<TMedicinal> page = new PageInfo<TMedicinal>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }

    @Override
    public List<TMedicinal> getOneMedic(TMedicinal tMedicinal) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MedicDao md = sqlSession.getMapper(MedicDao.class);
        sqlSession.clearCache();
        return md.getOneMedic(tMedicinal);
    }

    @Override
    public boolean addMedic(TMedicinal tMedicinal) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        MedicDao md = sqlSession.getMapper(MedicDao.class);
        int x = md.addMedic(tMedicinal);
        SqlSessionUtil.commit();
        sqlSession.close();
        return x > 0 ? true : false;
    }
}
